<?php

namespace app\admin\model;


class Porder extends Base
{
    // 表名
    protected $name = 'pur_order';
    // 追加属性
    protected $append = [
        'fk_bdl_orderstatus_text'
    ];

    public function getFkBdlOrderstatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['fk_bdl_orderstatus'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

//
//    //产品
//    public function material()
//    {
//        return $this->belongsTo("Material", 'fk_bdl_bd_material');
//    }
//
//    //库存
//    public function inventory()
//    {
//        return $this->belongsTo("Inventory", 'fk_bdl_inventoryid');
//    }
//    //订单关联
//    public function orderentry()
//    {
//        return $this->hasMany("Orderentry", 'id','id')->with(['material','inventory']);
//    }

    public function getStatusList()
    {
        return ["1" => "已下单", "2" => "装货中", "3" => "配送中", "4" => "已签收", "5" => "已退货", "6" => "待评价"];
    }

    public function getTypeList()
    {
        return ["1" => "现货", "2" => "定制"];
    }

    public function customer()
    {
        return $this->hasOne('Customer','id','fk_bdl_bd_customer');
    }

    public function cust()
    {
        return $this->hasOne('Customer','id','fk_bdl_bd_customer',[],'LEFT')->setEagerlyType(0);
    }

    public function address()
    {
        return $this->hasOne("Customeraddress",'id','fk_bdl_bd_useraddress');
    }

    public function carinfo()
    {
        return $this->hasOne('Carinfo','id','fk_bdl_bd_carinfo');
    }


}
